﻿using System;

namespace PMS.Data.Entities.Customers
{
    /// <summary>
    /// Represents a customer
    /// </summary>
    public partial class Customer : BaseEntity
    {
        public Customer()
        {
            CustomerGuid = Guid.NewGuid();
        }

        /// <summary>
        /// Gets or sets the customer GUID
        /// </summary>
        public Guid CustomerGuid { get; set; }

        /// <summary>
        /// Gets or sets the LoginName
        /// </summary>
        public string LoginName { get; set; }

        /// <summary>
        /// Gets or sets the Mobile Number
        /// </summary>
        public string Mobile { get; set; }

        /// <summary>
        /// Gets or sets the email
        /// </summary>
        public string Email { get; set; }

        /// <summary>
        /// Gets or sets the NickName for Display
        /// </summary>
        public string NickName { get; set; }
          
        /// <summary>
        /// Gets or sets the email that should be re-validated. Used in scenarios when a customer is already registered and wants to change an email address.
        /// </summary>
        public string EmailToRevalidate { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this customer has some products in the shopping cart
        /// <remarks>The same as if we run ShoppingCartItems.Count > 0
        /// We use this property for performance optimization:
        /// if this property is set to false, then we do not need to load "ShoppingCartItems" navigation property for each page load
        /// It's used only in a couple of places in the presenation layer
        /// </remarks>
        /// </summary>
        public bool HasShoppingCartItems { get; set; }

        /// <summary>
        /// CustomerSettings.PasswordLifetime 设置的密码过期时间(从上次修改密码时间起)判断账号是否需要重设密码，并通过通知消息提醒
        /// 方案一：通过后台计划任务定期自动执行，查询到密码过期的账号并设置该字段为true
        /// 方案二：设置Controller Attribute检查当前登录用户密码是否过期，并设置该字段
        /// 目前采用方案二,见ValidatePasswordAttribute
        /// </summary>
        public bool RequireChangingPwd { get; set; }

        /// <summary>
        /// Gets or sets a value indicating number of failed login attempts (wrong password)
        /// 通过CustomerSettings.FailedPasswordAllowedAttempts 设置的允许密码错误次数配合使用
        /// 当登录密码超过指定次数时，锁定账号：
        /// 1：设置限制登录时间 CannotLoginUntilDateUtc, 在限制时间未到之前不允许登录
        ///   通过CustomerSettings.FailedPasswordLockoutMinutes计算限制登录时长
        /// 2：如果限制登录时间到后重登录依然校验密码错误，设置下次限制登录时长同时累加错误登录次数
        ///  到达CustomerSettings.TotalFailedAllowedAttemps所设置的允许登录错误尝试次数后，不再设置下次限制登录时长，
        ///  而是锁定账号 IsActive=true,锁定账号后只能后台系统有用户操作权限的账号重置密码或者用户通过"忘记密码"功能重置密码
        /// </summary>
        public int FailedLoginAttempts { get; set; }

        /// <summary>
        /// Gets or sets the date and time until which a customer cannot login (locked out)
        /// </summary>
        public DateTime? CannotLoginUntilDateUtc { get; set; }

        //IsActive: Seted in BaseEntity
        //账号是否正常： true: 正常，允许登录访问
        //            false:锁定，see comment of FailedLoginAttempts
        //public bool IsActive { get; set; }
        /// <summary>
        /// Gets or sets a value indicating whether the customer has been deleted
        /// true: Account Deleted/ Set Email/Mobile/LoginName with prefix "Deleted-"
        /// false:Account available
        /// </summary>
        public bool IsDeleted { get; set; }

        /// <summary>
        /// Gets or sets the last Login IP address
        /// </summary>
        public string LastLoginIpAddress { get; set; }

        /// <summary>
        /// Gets or sets the date and time of last login
        /// </summary>
        public DateTime? LastLoginTimeUtc { get; set; }

        /// <summary>
        /// Gets or sets the date and time of last activity
        /// </summary>
        public DateTime LastActivityTimeUtc { get; set; }

        /// <summary>
        ///  Gets or sets the store identifier in which customer registered
        /// </summary>
        public int RegisteredInStoreId { get; set; }

    }
}
